// components/preview-img-description/preview-img-description.js
Component({
    options: {
        addGlobalClass: true
    },
    properties: {
        imgUrls: {
            type: Array,
            value: [],
            observer: function observer(newVal, oldVal, changedPath) {
                this.setData({
                    currentImgs: newVal
                });
            }
        },
        description: {
            type: Array,
            value: ['描述三十六撒旦记录卡集散地立刻卡罗拉集散地立刻进来咯技术的了离开家拉克斯基的了空间啊十三点', '描述三十六撒旦的了离开家拉克斯基的了空间啊十三点', '描述三十六撒旦的了离开家拉克斯基的了空间啊十三点描述三十六撒旦记录卡集散地立刻卡罗拉集散地立刻进来咯技术的了离开家拉克斯基的了空间啊十三点']
        },
        show: {
            type: Boolean,
            value: true
        },
        current: {
            type: Number,
            value: 0
        },
        hideOnClick: {
            type: Boolean,
            value: true
        },
        extClass: {
            type: Boolean,
            value: ''
        }
    },
    data: {
        currentImgs: ['https://image.weilanwl.com/img/4x3-1.jpg', 'http://1844.img.pp.sohu.com.cn/images/blog/2010/2/3/21/18/12744ebb530g213.jpg', 'https://image.weilanwl.com/img/4x3-1.jpg', 'https://image.weilanwl.com/img/4x3-1.jpg'],
        duration: 500,
    },
    ready: function ready() {
        // var data = this.data;
        // this.setData({
        //     duration: 500
        // });
    },

    methods: {
        change: function change(e) {
            this.setData({
                current: e.detail.current
            });
            this.triggerEvent('change', {
                current: e.detail.current
            }, {});
        },
        deleteImg: function deleteImg() {
            var data = this.data;
            var imgs = data.currentImgs;
            var url = imgs.splice(data.current, 1);
            this.triggerEvent('delete', {
                url: url[0],
                index: data.current
            }, {});
            if (imgs.length === 0) {
                this.hideGallery();
                return;
            }
            this.setData({
                current: 0,
                currentImgs: imgs
            });
        },
        hideGallery: function hideGallery() {
            var data = this.data;
            if (data.hideOnClick) {
                this.setData({
                    show: false
                });
                this.triggerEvent('hide', {}, {});
            }
        }
    }
});